import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.script.Script;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.methods.Camera;
import org.rsbot.script.methods.Game;
import org.rsbot.script.methods.Inventory;
import org.rsbot.script.methods.Objects;
import org.rsbot.script.methods.Skills;
import org.rsbot.script.wrappers.RSItem;
import org.rsbot.script.wrappers.RSObject;
import org.rsbot.script.wrappers.RSPlayer;

@ScriptManifest(authors={"LastCoder"}, name="Iron PowerMiner", version=1.0D, description="Any Location, just start near rocks.")
public class PowerMiner extends Script
  implements PaintListener
{
  private static final int[] ROCKS = { 11956, 11954, 11955, 37307, 37308, 37309 };
  private static final int IRON_ITEM = 440;
  private static final int TRAINING_SKILL = 14;
  private static final Color COLOR_1 = new Color(0, 0, 0, 154);
  private static final Color COLOR_2 = new Color(0, 0, 0, 147);
  private static final Color COLOR_3 = new Color(255, 255, 255);
  private static final Font FONT_1 = new Font("Arial", 0, 12);
  private static final Font FONT_2 = new Font("Arial", 0, 10);
  private static final BasicStroke STROKE_1 = new BasicStroke(1.0F);
  private long startExp;
  private long startLevel;
  private long startTime;
  private long expGained;
  private int expHour;

  private PowerMiner.State getState()
  {
    if (this.inventory.isFull()) {
      return PowerMiner.State.DROP;
    }
    return PowerMiner.State.MINE;
  }

  public int loop()
  {
    switch (PowerMiner.1.$SwitchMap$PowerMiner$State[getState().ordinal()]) {
    case 1:
      RSObject localRSObject = this.objects.getNearest(ROCKS);
      if (localRSObject == null)
        break;
      int i;
      if (!localRSObject.isOnScreen()) {
        this.camera.turnToObject(localRSObject);
        for (i = 0; (i < 100) && (!localRSObject.isOnScreen()); i++)
          sleep(20);
      } else {
        for (i = 0; (i < 100) && (getMyPlayer().isMoving()); i++)
          sleep(20);
        localRSObject.doAction("Mine");
        i = 0;
        for (; (i < 100) && (getMyPlayer().getAnimation() != -1); i++)
          sleep(20);
      }
      break;
    case 2:
      RSItem[] arrayOfRSItem1 = this.inventory.getItems();
      for (RSItem localRSItem : arrayOfRSItem1) {
        if (localRSItem == null)
          continue;
        if (localRSItem.getID() == 440) {
          localRSItem.doAction("Drop");
          sleep(100);
        }
      }

    }

    return 0;
  }

  public boolean onStart() {
    this.startExp = this.skills.getCurrentExp(14);
    this.startLevel = this.skills.getRealLevel(14);
    this.startTime = System.currentTimeMillis();
    return this.game.isLoggedIn();
  }

  public void onRepaint(Graphics paramGraphics) {
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    long l1 = System.currentTimeMillis() - this.startTime;
    long l2 = l1 / 1000L;
    long l3 = l1 / 3600000L;
    l1 -= l3 * 1000L * 60L * 60L;
    long l4 = l1 / 60000L;
    l1 -= l4 * 1000L * 60L;
    long l5 = l1 / 1000L;
    if ((this.skills.getCurrentExp(14) - this.startExp > 0L) && (this.startExp > 0L))
    {
      this.expGained = (this.skills.getCurrentExp(14) - this.startExp);
    }
    if ((this.expGained > 0L) && (l2 > 0L)) {
      this.expHour = (int)(3600L * this.expGained / l2);
    }
    localGraphics2D.setColor(COLOR_1);
    localGraphics2D.fillRect(366, 4, 135, 106);
    localGraphics2D.setColor(COLOR_2);
    localGraphics2D.setStroke(STROKE_1);
    localGraphics2D.drawRect(366, 4, 135, 106);
    localGraphics2D.setFont(FONT_1);
    localGraphics2D.setColor(COLOR_3);
    localGraphics2D.drawString("Iron PowerMiner", 393, 22);
    localGraphics2D.setFont(FONT_2);
    localGraphics2D.drawString("Time Run: " + l3 + " : " + l4 + " : " + l5, 370, 40);

    localGraphics2D.drawString("EXP Gained: " + this.expGained, 370, 55);
    localGraphics2D.drawString("EXP/Hr: " + this.expHour, 370, 70);
    localGraphics2D.drawString("Levels Gained: (" + this.startLevel + ") Gained: " + (this.skills.getRealLevel(14) - this.startLevel), 370, 85);
  }
}